/*
 * BanBu_ProfileDataController
 * @description 本文件提供个人空间的用户个人信息界面的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供个人空间的用户个人信息界面的ViewController
 */
#import "BanBu_ProfileDataController.h"
#import "BanBu_NameAndSexController.h"
#import "BanBu_BirthdayViewController.h"
#import "BanBu_WorkViewController.h"
#import "NSDictionary_JSONExtensions.h"
#import "AppCommunicationManager.h"
#import "AppDataManager.h"
#import "TKLoadingView.h"
#import "BanBu_AppDelegate.h"
#import "BanBu_NavButton.h"
#import "BanBu_ImageView.h"
#import "CJSONSerializer.h"
#import "UIViewController+Animation.h"
#import "BanBu_BloodTypeAndHeightController.h"
#import "BanBu_VideoAuthenViewController.h"
#import "BanBu_ApplyVipViewController.h"
#import "BanBu_VIPAlert.h"
#import "BanBu_SecondVerifyViewController.h"
#import "BanBu_MWNavigationController.h"
#import "BanBu_PersonDataHeader.h"
#import "BanBu_SnowFall.h"
@interface BanBu_ProfileDataController ()

@end

@implementation BanBu_ProfileDataController

@synthesize myProfile = _myProfile;
@synthesize imagePathExtension = _imagePathExtension;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithProfile:(NSDictionary *)_profile
{
    self = [super init];
    if (self)
    {
        _myProfile = [[NSMutableDictionary alloc] initWithDictionary:[self buildMyProfile:_profile]];

    }
    return self;
}

-(void)abc:(NSNotification *)notifi{
    
    
    [UserDefaults setValue:@"fb" forKey:@"FBUser"];
    NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:2];
    [pars setValue:@"facebook" forKey:@"bindto"];
    [pars setValue:[NSString stringWithFormat:@"%@,%@",[(FBSession *)[notifi object] accessTokenData].accessToken,@"fb"] forKey:@"bindstring"];
    [AppComManager getBanBuData:BanBu_Set_User_accountbind par:pars delegate:self];
    [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"chuliNotice", nil) activityAnimated:YES];
    self.navigationController.view.userInteractionEnabled = NO;
}

-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)getMyInfo
{
    [AppComManager getBanBuData:BanBu_Get_My_Info par:[NSDictionary dictionary] delegate:self];
}

#pragma mark - show and hide the keyboard
- (void)setUpForDismissKeyboard {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    UITapGestureRecognizer *singleTapGR =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(tapAnywhereToDismissKeyboard:)];
    NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];
    [nc addObserverForName:UIKeyboardWillShowNotification
                    object:nil
                     queue:mainQuene
                usingBlock:^(NSNotification *note){
                    [self.view addGestureRecognizer:singleTapGR];
                }];
    [nc addObserverForName:UIKeyboardWillHideNotification
                    object:nil
                     queue:mainQuene
                usingBlock:^(NSNotification *note){
                    [self.view removeGestureRecognizer:singleTapGR];
                }];
}

- (void)tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer {
    //此method会将self.view里所有的subview的first responder都resign掉
    [self.view endEditing:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUpForDismissKeyboard];
    _socialInfo = [[NSMutableDictionary alloc] initWithCapacity:0];
    [_socialInfo addEntriesFromDictionary:[UserDefaults valueForKey:@"snslist"]];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(abc:) name:@"abc" object:nil];
    self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    self.tableView.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    self.title =[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"pname"];
//    [self getMyInfo];
    
    BanBu_ImageView *backImage = [[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable];
    self.tableView.backgroundView = backImage;
    [backImage release];
    
    [AppComManager getBanBuData:BanBu_Get_User_Sns_Idlist par:[NSDictionary dictionaryWithObjectsAndKeys:MyAppDataManager.useruid,@"userid", nil] delegate:self];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.myProfile = nil;
}

- (void)dealloc
{
    [shareString release],shareString = nil;
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"abc" object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"Twitter" object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"bindSuccess" object:nil];
    
    
    [_socialInfo release],_socialInfo = nil;
    [_myProfile release],_myProfile = nil;
    [_editBuffer release],_editBuffer =nil;
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [AppComManager cancalHandlesForObject:self];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return [[_myProfile valueForKey:@"sections"] count];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",section]] count]+1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 50;
    }
    NSInteger row = indexPath.row-1;
    if(indexPath.section == 3)
    {
        return 90;
    }

    NSString *cellTitle = [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",indexPath.section]] objectAtIndex:row];
    NSDictionary *adata = [_myProfile valueForKey:cellTitle];
    if(![[adata valueForKey:@"showType"] boolValue])
        return 10+40;
    
    NSString *detailValue = [adata valueForKey:@"realValue"];
    if(![detailValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length){
        detailValue = [adata valueForKey:@"DefaultValue"];
        return 10+[detailValue sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(250, 1000)].height+30;
    }else{
        return 10+[detailValue sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(255, 1000)].height+30;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    view.backgroundColor = [UIColor clearColor];//根据需求改变着个颜色不需要改为clear
    return [view autorelease];
}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 10;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    view.backgroundColor = [UIColor clearColor];//根据需求改变着个颜色不需要改为clear
    return [view autorelease];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        static NSString *cellIndentifer = @"cellindentifierrrrrrr";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifer];
        if(!cell)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIndentifer] autorelease];
            cell.backgroundColor = [UIColor whiteColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        else
        {
            for(UIView *v in cell.contentView.subviews)
            {
                [v removeFromSuperview];
            }
        }
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(30, 1, 250, 48)];
        lab.font = [UIFont boldSystemFontOfSize:16];
        lab.numberOfLines = 1;
        lab.backgroundColor = [UIColor clearColor];
        lab.textColor = [UIColor blackColor];
        [cell.contentView addSubview:lab];
        [lab release];
        
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 25, 25)];
        [cell.contentView addSubview:img];
        [img release];
        if(indexPath.section == 0)
        {
            lab.text= NSLocalizedString(@"profileSection3", nil);
            img.image = [UIImage imageNamed:@"zhanghaoxinxi.png"];
        }
        else if(indexPath.section == 1)
        {
            lab.text= NSLocalizedString(@"profileSection", nil);
            img.image = [UIImage imageNamed:@"jibenxinxi.png"];
        }
        else if(indexPath.section == 2)
        {
            lab.text= NSLocalizedString(@"profileSection1", nil);
            img.image = [UIImage imageNamed:@"gerenxinxi.png"];
        }
        else if(indexPath.section == 3)
        {
            lab.text= NSLocalizedString(@"socialNetwork", nil);
            img.image = [UIImage imageNamed:@"shejiaowangluo.png"];
        }
        else if(indexPath.section == 4)
        {
            lab.text= NSLocalizedString(@"profileSection3", nil);
            img.image = [UIImage imageNamed:@"shejiaowangluo.png"];
        }
        return cell;
        
    }
    
    NSInteger row = indexPath.row-1;

    NSString *cellTitle = [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",indexPath.section]] objectAtIndex:row];
    NSDictionary *adata = [_myProfile valueForKey:cellTitle];
    
    BOOL showType = [[adata valueForKey:@"showType"] boolValue];
    
    static NSString *cellIndentifera = @"cellindentifierrraaa";
    static NSString *cellIndentiferb = @"cellindentifierrrbbb";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:showType?cellIndentifera:cellIndentiferb];
    if(!cell)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:showType?UITableViewCellStyleSubtitle:UITableViewCellStyleValue1 reuseIdentifier:showType?cellIndentifera:cellIndentiferb] autorelease];
    }
    else
    {
        cell.detailTextLabel.text = @"";
        cell.textLabel.text = @"";
        
        for(UIView *v in cell.contentView.subviews)
        {
            [v removeFromSuperview];
        }
        
    }
    cell.detailTextLabel.numberOfLines = 0;
    cell.textLabel.text = cellTitle;
    
    cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.hidden = NO;
    cell.detailTextLabel.hidden = NO;
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]&&IS_IOS_7)
    {
        [tableView setSeparatorInset:UIEdgeInsetsMake(0, 45, 0, 0)];
    }
    
    if(indexPath.section != 3)
    {
        if([[adata valueForKey:@"canEdit"] boolValue])
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        else
            cell.accessoryType = UITableViewCellAccessoryNone;
        
        if([[adata valueForKey:@"realValue"] isEqualToString:NSLocalizedString(@"unVerify", nil)])
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        
        NSString *detailValue = [adata valueForKey:@"realValue"];
        if(![detailValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length)
        {
            cell.detailTextLabel.textColor = [UIColor colorWithWhite:0.7 alpha:1];
            detailValue = [adata valueForKey:@"DefaultValue"];
        }
        else
            cell.detailTextLabel.textColor = [UIColor colorWithRed:56.0/255 green:84.0/255 blue:135.0/255 alpha:1.0];
        
        
        cell.detailTextLabel.font =  [UIFont systemFontOfSize:14];
        
        cell.detailTextLabel.text = detailValue;
        if(row == 4&&indexPath.section == 0&&[cellTitle isEqualToString:NSLocalizedString(@"videoVerify", nil)])
        {
            
            if([detailValue isEqualToString:NSLocalizedString(@"unVerify", nil)])
            {
                cell.detailTextLabel.textColor = [UIColor redColor];
                cell.detailTextLabel.hidden = NO;
            }
            else
            {
                cell.detailTextLabel.hidden = YES;
                UIImageView *yImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"isVerified.png"]];
                yImage.frame = CGRectMake(__MainScreen_Width-10-10-20-40, 15, 20, 20);
                [cell.contentView addSubview:yImage];
                [yImage release];
                
                UIImageView *img = [[UIImageView alloc] init];
                [img setImageWithURL:[NSURL URLWithString:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"image_verify"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:0];
                img.frame = CGRectMake(__MainScreen_Width-10-10-10, 15, 20, 20);
                img.center = CGPointMake(__MainScreen_Width-10-20-10, 25);
                [cell.contentView addSubview:img];
                [img release];
            }
        }
        else if (row == 5&&indexPath.section == 0&&[cellTitle isEqualToString:NSLocalizedString(@"VIPMember", nil)])
        {
            if([detailValue isEqualToString:NSLocalizedString(@"VIPRightListTitle", nil)])
            {
                cell.detailTextLabel.hidden = YES;
                UIImageView *yImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"isVerified.png"]];
                yImage.frame = CGRectMake(__MainScreen_Width-10-10-20-40, 15, 20, 20);
                [cell.contentView addSubview:yImage];
                [yImage release];
                
                UIImageView *img = [[UIImageView alloc] init];
                [img setImageWithURL:[NSURL URLWithString:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"image_verify"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:0];
                img.frame = CGRectMake(__MainScreen_Width-10-10-10, 15, 20, 20);
                img.center = CGPointMake(__MainScreen_Width-10-20-10, 25);
                [cell.contentView addSubview:img];
                [img release];
            }
        }
    }
    else
    {
        
        cell.textLabel.text = @"";
        cell.detailTextLabel.text = @"";
        NSArray *netImageArr= nil;
        NSArray *nameArr = nil;
        NSArray *paramArr = nil;
        cell.accessoryType = UITableViewCellAccessoryNone;
        if([[MyAppDataManager getLanguageSubmitToServer] isEqualToString:@"cn"])
        {
            netImageArr = [NSArray arrayWithObjects:@"sina_social.png",@"tencent_social.png",@"weichat_social.png",@"momo_social.png", nil];
            nameArr     = [NSArray arrayWithObjects:@"新浪微博",@"腾讯微博",@"微信",@"陌陌",nil];
            paramArr = [NSArray arrayWithObjects:@"sina",@"tencent",@"wechat",@"momo",nil];
            
            
        }
        else if([[MyAppDataManager getLanguageSubmitToServer] isEqualToString:@"jp"])
        {
            netImageArr = [NSArray arrayWithObjects:@"fb_social.png",@"twiter_social.png",@"line_social.png",@"kakao_social.png", nil];
            nameArr     = [NSArray arrayWithObjects:@"Facebook",@"Twitter",@"LINE",@"Kakao",nil];
            paramArr = [NSArray arrayWithObjects:@"facebook",@"twitter",@"line",@"kakao",nil];
            
        }
        else
        {
            netImageArr = [NSArray arrayWithObjects:@"fb_social.png",@"twiter_social.png",@"instagram_social.png",@"kik_social.png", nil];
            nameArr     = [NSArray arrayWithObjects:@"Facebook",@"Twitter",@"Instagram",@"Kik",nil];
            paramArr = [NSArray arrayWithObjects:@"facebook",@"twitter",@"instagram",@"kik",nil];
            
        }
        UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[netImageArr objectAtIndex:row]]];
        img.frame = CGRectMake(45, 10, 50, 50);
        [cell.contentView addSubview:img];
        [img release];
        //        cell.detailTextLabel.text = NSLocalizedString(@"noAdd", nil);
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 65, 60, 15)];
        label.font = [UIFont systemFontOfSize:13];
        label.backgroundColor = [UIColor clearColor];
        label.text = [nameArr objectAtIndex:row];
        label.textAlignment = kTextAlignmentCenter;
        [cell.contentView addSubview:label];
        [label release];
        UITextField *textField ;
      
        if (IS_IOS_7)
        {
            textField = [[UITextField alloc] initWithFrame:CGRectMake(150, 30, 160, 30)];
        }
        else
        {
            textField = [[UITextField alloc] initWithFrame:CGRectMake(130, 30, 160, 30)];
        }
        textField.textAlignment = kTextAlignmentRight;
        textField.backgroundColor = [UIColor clearColor];
        textField.delegate = self;
        textField.tag = indexPath.row * 123;
        textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        //        textField.hidden = YES;
        if(![[_socialInfo  valueForKey:[paramArr objectAtIndex:row]] length])
        {
            textField.text = NSLocalizedString(@"noAdd", nil);
        }
        else
        {
            textField.text = [_socialInfo  valueForKey:[paramArr objectAtIndex:row]];
        }
        
        textField.font = [UIFont systemFontOfSize:16];
        textField.borderStyle = UITextBorderStyleNone;
        textField.textColor = [UIColor colorWithRed:50.0/255 green:79.0/255 blue:133.0/255 alpha:1.0];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.returnKeyType = UIReturnKeyNext;
        [cell.contentView addSubview:textField];
        [textField release];
          }
    
    if([[adata valueForKey:@"canedit"] boolValue])
    {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }
    else
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if(indexPath.row == 0)
    {
        return;
    }
    if(indexPath.section == 3)
    {
        UITextField *textField = (UITextField *)[tableView viewWithTag:indexPath.row *123];
        textField.hidden = NO;
        [textField becomeFirstResponder];
    }
    else
    {
        NSInteger row = indexPath.row-1;
        NSString *cellTitle = [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",indexPath.section]] objectAtIndex:row];
        NSDictionary *adata = [_myProfile valueForKey:cellTitle];
        if([[adata valueForKey:@"canEdit"] boolValue])
        {
            NSString *cellTitle = [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",indexPath.section]] objectAtIndex:row];
 
            //名字
            if([cellTitle isEqualToString:NSLocalizedString(@"nameLabel", nil)]||[cellTitle isEqualToString:NSLocalizedString(@"sexlabel", nil)])
            {
                NSDictionary *adata = [_myProfile valueForKey:cellTitle];
                BanBu_NameAndSexController *name = [[BanBu_NameAndSexController alloc] initWithViewType:NameAndSexViewNameOnlyType];
                [self.navigationController pushViewController:name animated:YES];
                name.delegate = self;
                name.name = [adata valueForKey:@"realValue"];
                name.sex = [[[_myProfile valueForKey:@"gender"] valueForKey:@"realValue"] boolValue];
                [name release];
            }
            //年龄
            else if([cellTitle isEqualToString:NSLocalizedString(@"ageLabel", nil)])
            {
                BanBu_BirthdayViewController *birth = [[BanBu_BirthdayViewController alloc] init];
                birth.birthdayDefault = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"borndate"];
                birth.delegate = self;
                birth.viewType = BirthdayViewNameOnlyType;
                [self.navigationController pushViewController:birth animated:YES];
                [birth release];
            }
            //身高 血型 体重
            else if([cellTitle isEqualToString:NSLocalizedString(@"s1c0", nil)]||[cellTitle isEqualToString:NSLocalizedString(@"s1c1", nil)]||[cellTitle isEqualToString:NSLocalizedString(@"s1c2", nil)])
            {
                BanBu_BloodTypeAndHeightController *blood = [[BanBu_BloodTypeAndHeightController alloc] init];
                blood.viewType = BloodTypeAndHeightOnlyType;
                blood.delegate = self;
                [blood setDefaultSelectIndexHeight:[[_myProfile valueForKey:NSLocalizedString(@"s1c0", nil)] valueForKey:@"realValue"] Weight:[[_myProfile valueForKey:NSLocalizedString(@"s1c2", nil)] valueForKey:@"realValue"] Blood:[[_myProfile valueForKey:NSLocalizedString(@"s1c1", nil)] valueForKey:@"realValue"]];
                [self.navigationController pushViewController:blood animated:YES];
                [blood release];
            }
            //职业
            else if([cellTitle isEqualToString:NSLocalizedString(@"s2c3", nil)])
            {
                NSString *zhiyeStr = [[[_myProfile valueForKey:cellTitle] valueForKey:@"realValue"] stringByReplacingOccurrencesOfString:@"／" withString:@"/"];
                NSArray *workArr =  [[NSArray alloc] initWithObjects:NSLocalizedString(@"workItem", nil),NSLocalizedString(@"workItem1", nil),NSLocalizedString(@"workItem2", nil),NSLocalizedString(@"workItem3", nil),NSLocalizedString(@"workItem4", nil),NSLocalizedString(@"workItem5", nil),NSLocalizedString(@"workItem6", nil),NSLocalizedString(@"workItem7", nil),NSLocalizedString(@"workItem8", nil),NSLocalizedString(@"workItem9", nil),NSLocalizedString(@"workItem10", nil), nil];
                
                if([zhiyeStr isEqualToString:@""]){
                    BanBu_WorkViewController *work = [[BanBu_WorkViewController alloc]initWithWorkInfo:@"" type:0];
                    work.delegate = self;
                    [self.navigationController pushViewController:work animated:YES];
                    [work release];
                }else{
                    zhiyeStr = [zhiyeStr stringByReplacingOccurrencesOfString:@"-" withString:@"－"];
                    NSArray *doubleArr = [NSArray arrayWithArray:[zhiyeStr componentsSeparatedByString:@"－"]];
                    //NSLog(@"%@",doubleArr);
                    for (int i =0 ; i<workArr.count; i++) {
                        if([[doubleArr objectAtIndex:0] isEqualToString:[workArr objectAtIndex:i]]){
                            _workType = i;
                            break;
                            
                        }
                    }
                    
                    BanBu_WorkViewController *work = [[BanBu_WorkViewController alloc]initWithWorkInfo:[doubleArr objectAtIndex:1] type:_workType];
                    work.delegate = self;
                    [self.navigationController pushViewController:work animated:YES];
                    [work release];
                }
                [workArr release];
            }
            //个人签名 兴趣爱好 常出没的地方 公司 学校 等
            else
            {
                NSString *cellTitle = [[_myProfile valueForKey:[NSString stringWithFormat:@"%i",indexPath.section]] objectAtIndex:row];
                NSDictionary *adata = [_myProfile valueForKey:cellTitle];
                if([[adata valueForKey:@"canEdit"] boolValue])
                {
                    
                    BanBu_TextEditer *editer;
                    /*将个人资料未做多语言存储就出问题了，要注释掉下边的语句，当初为啥添的忘了。*/
                    //因为英文的名字太长了。。。
                    //                if(indexPath.section == 0){
                    //                    cellTitle = @"Signature";
                    //                }
                    //                if(indexPath.section == 2){
                    //                    if(row == 0){
                    //                        cellTitle = @"Interests";
                    //                    }
                    //                }
                    
                    editer = [[BanBu_TextEditer alloc] initWithTitle:cellTitle oldText:[adata valueForKey:@"realValue"] description:[adata valueForKey:@"DefaultValue"]];
                    
                    
                    editer.delegate = self;
                    [self.navigationController pushViewController:editer animated:YES];
                    [editer release];
                }
                else
                    [tableView deselectRowAtIndexPath:indexPath animated:YES];
            }
            
                
                
            
        }
        else if ([[adata valueForKey:@"realValue"] isEqualToString:NSLocalizedString(@"unVerify", nil)])
        {
            [[BanBu_VIPAlert shareInstance] GoVerifyApplyViewAlertFor:self.parentViewController title:NSLocalizedString(@"videoVerify", nil) message:NSLocalizedString(@"verifyNoticeAlert", nil)];
        }
        
        //再次认证 by yinlin 2014年08月07日13:18:15
        else if ([[adata valueForKey:@"realValue"] isEqualToString:NSLocalizedString(@"alreadyVerify", nil)])
        {
            MyAppDataManager.personCon = self.parentViewController ;
            BanBu_SecondVerifyViewController *reverify = [[BanBu_SecondVerifyViewController alloc] initWithVerifyPhoto:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"image_verify"]];
            [self.navigationController pushViewController:reverify animated:YES];
            [reverify release];
        }
        
        else if ([[adata valueForKey:@"realValue"] isEqualToString:NSLocalizedString(@"applyNow", nil)])
        {
            BanBu_ApplyVipViewController *video = [[BanBu_ApplyVipViewController alloc] init];
            [self.navigationController pushViewController:video animated:YES];
            [video release];
        }
    }
}

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return 1;
}

- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    MWPhoto *verifyPhoto = [[MWPhoto photoWithURL:[NSURL URLWithString:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"image_verify"]]] retain];
    return verifyPhoto;
}

#pragma mark - 获取当前机器语言
// 获取当前机器语言
-(NSString*)getPreferredLanguage
{
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    NSString* preferredLang = [languages objectAtIndex:0];
    return preferredLang;
}

#pragma mark - 创建个人信息显示数据
- (NSDictionary *)buildMyProfile:(NSDictionary *)_dataDic
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithDictionary:_dataDic];
    NSMutableDictionary *myData = [[NSMutableDictionary alloc] initWithCapacity:1];
    NSArray *titles = nil;
    NSDictionary *data = nil;
    
    NSDate *date = [[UserDefaults valueForKey:[NSString stringWithFormat:@"modify%@",MyAppDataManager.useruid]]valueForKey:@"modifyDate"];
    if([date timeIntervalSinceNow]<60*60*24)
    {
        [_checkingData setValue:[NSDate date] forKey:@"modifyDate"];
        [dataDic addEntriesFromDictionary:[UserDefaults valueForKey:[NSString stringWithFormat:@"modify%@",MyAppDataManager.useruid]]];
        [dataDic removeObjectForKey:@"modifyDate"];
    }
    else
    {
        [UserDefaults removeObjectForKey:[NSString stringWithFormat:@"modify%@",MyAppDataManager.useruid]];
    }
    
    
    
    
    NSString *sex = [[dataDic valueForKey:@"gender"] isEqualToString:@"m"]?@"y":@"n";
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"y",@"DefaultValue",sex,@"realValue",@"0",@"showType",nil];
    [myData setValue:data forKey:@"gender"];
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"oldyears"],@"realValue",@"0",@"showType",nil];
    [myData setValue:data forKey:@"oldyears"];
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"sstar"],@"realValue",@"0",@"showType",nil];
    [myData setValue:data forKey:@"sstar"];
    
    

    BOOL canEditNS = YES;
    if([[dataDic allKeys]indexOfObject:@"locka"] != NSNotFound)
    {
        canEditNS = ![[dataDic valueForKey:@"locka"] boolValue];
    }
    BOOL canEditA = YES;
    if([[dataDic allKeys]indexOfObject:@"lockb"] != NSNotFound)
    {
        canEditA = ![[dataDic valueForKey:@"lockb"] boolValue];
    }
    titles = [NSArray arrayWithObjects:NSLocalizedString(@"s0c0", nil),NSLocalizedString(@"nameLabel",nil),NSLocalizedString(@"ageLabel", nil),NSLocalizedString(@"s0c2", nil),NSLocalizedString(@"videoVerify", nil),NSLocalizedString(@"VIPMember", nil), nil];
    
    [myData setValue:titles forKey:@"0"];
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"userid"],@"realValue",@"0",@"showType",nil];
    [myData setValue:data forKey:[titles objectAtIndex:0]];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"pname"],@"realValue",@"0",@"showType",[NSString stringWithFormat:@"%d",canEditNS],@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:1]];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"oldyears"],@"realValue",@"0",@"showType",[NSString stringWithFormat:@"%d",canEditA],@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:2]];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s0c2DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"sayme"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:3]];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"videoVerify", nil),@"DefaultValue",[[dataDic valueForKey:@"verify"] boolValue]?NSLocalizedString(@"alreadyVerify", nil):NSLocalizedString(@"unVerify", nil),@"realValue",@"0",@"showType",@"0",@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:4]];
    
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"VIPMember", nil),@"DefaultValue",[[dataDic valueForKey:@"userlevel"] integerValue]>0?NSLocalizedString(@"VIPRightListTitle", nil):NSLocalizedString(@"applyNow", nil),@"realValue",@"0",@"showType",@"0",@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:5]];
    
    //1 section
    titles = [NSArray arrayWithObjects:NSLocalizedString(@"s1c0", nil),NSLocalizedString(@"s1c1", nil),NSLocalizedString(@"s1c2", nil),nil] ;
    [myData setValue:titles forKey:@"1"];
    BOOL canEditHXW = YES;
    if([[dataDic allKeys]indexOfObject:@"lockc"] != NSNotFound)
    {
        canEditHXW = ![[dataDic valueForKey:@"lockc"] boolValue];
    }
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"hbody"],@"realValue",@"0",@"showType",[NSString stringWithFormat:@"%d",canEditHXW],@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:0]];
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"xblood"],@"realValue",@"0",@"showType",[NSString stringWithFormat:@"%d",canEditHXW],@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:1]];
    data = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"DefaultValue",[dataDic valueForKey:@"wbody"],@"realValue",@"0",@"showType",[NSString stringWithFormat:@"%d",canEditHXW],@"canEdit",nil];
    [myData setValue:data forKey:[titles objectAtIndex:2]];
    
    
    //2 section
    titles = [NSArray arrayWithObjects:NSLocalizedString(@"s2c0", nil),NSLocalizedString(@"s2c1", nil),NSLocalizedString(@"s2c2", nil),NSLocalizedString(@"s2c3", nil),NSLocalizedString(@"s2c4", nil),nil];
    [myData setValue:titles forKey:@"2"];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s2c0DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"liked"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    
    [myData setValue:data forKey:[titles objectAtIndex:0]];
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s2c1DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"lovego"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    
    [myData setValue:data forKey:[titles objectAtIndex:1]];
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s2c2DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"company"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    
    [myData setValue:data forKey:[titles objectAtIndex:2]];
    
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s2c3DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"jobtitle"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    //
    [myData setValue:data forKey:[titles objectAtIndex:3]];
    data = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s2c4DefaluteValue", nil),@"DefaultValue",[dataDic valueForKey:@"school"],@"realValue",@"1",@"showType",@"1",@"canEdit",nil];
    
    [myData setValue:data forKey:[titles objectAtIndex:4]];

    
    //3 section
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    NSString* preferredLang = [languages objectAtIndex:0];
    if([preferredLang isEqual:@"zh-Hans"]){
        titles = [NSArray arrayWithObjects:NSLocalizedString(@"s3c0", nil),NSLocalizedString(@"s3c1", nil),NSLocalizedString(@"s3c1", nil),NSLocalizedString(@"s3c1", nil), nil];
        [myData setValue:titles forKey:@"3"];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:0]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:1]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:2]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:3]];
    }else{
        titles = [NSArray arrayWithObjects:@"Twitter",@"Facebook",@"Twitter",@"Facebook",nil];
        [myData setValue:titles forKey:@"3"];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:0]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:1]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:2]];
        data = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"realValue",@"0",@"showType",nil];
        [myData setValue:data forKey:[titles objectAtIndex:3]];
        
        
    }
    
    
    
    id faces = [dataDic valueForKey:@"facelist"];
    if([faces isKindOfClass:[NSArray class]])
    {
        [myData setValue:faces forKey:@"facelist"];
        
    }
    
    [myData setValue:[NSArray arrayWithObjects:@"0",@"1",@"2",@"3", nil] forKey:@"sections"];
    [myData setValue:[dataDic valueForKey:@"userid"] forKey:@"userid"];
    [myData setValue:[dataDic valueForKey:@"uface"] forKey:KeyUface];
    
    [pool drain];
    
    //    NSLog(@"%@",myData);
    return [myData autorelease];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if([textField.text isEqualToString:NSLocalizedString(@"noAdd", nil)])
    {
        textField.text = @"";
    }
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    NSInteger index = textField.tag/123-1;
    NSArray *paramArr = nil;
    if([[MyAppDataManager getLanguageSubmitToServer] isEqualToString:@"cn"])
    {
        paramArr = [NSArray arrayWithObjects:@"sina",@"tencent",@"wechat",@"momo",nil];
        
    }
    else if([[MyAppDataManager getLanguageSubmitToServer] isEqualToString:@"jp"])
    {
        paramArr = [NSArray arrayWithObjects:@"facebook",@"twitter",@"line",@"kakao",nil];
    }
    else
    {
        paramArr = [NSArray arrayWithObjects:@"facebook",@"twitter",@"instagram",@"kik",nil];
    }
    [_socialInfo setValue:textField.text forKey:[paramArr objectAtIndex:index]];
    if(!textField.text.length)
    {
        [_socialInfo setValue:@"" forKey:[paramArr objectAtIndex:index]];
    }
    NSString *socialist = [[CJSONSerializer serializer] serializeDictionary:_socialInfo];
    
    [AppComManager getBanBuData:BanBu_Set_User_Sns_Idlist par:[NSDictionary dictionaryWithObjectsAndKeys:socialist,@"snslist",nil] delegate:self];
    [textField resignFirstResponder];
    if(!textField.text.length)
    {
        textField.text = NSLocalizedString(@"noAdd", nil);
    }
}
- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    self.navigationController.view.userInteractionEnabled = YES;
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:YES afterShow:0.0];
    NSLog(@"%@",resDic);
    if(error)
    {
        if([AppComManager respondsDic:resDic isFunctionData:BanBu_Del_My_Avatar] || [AppComManager respondsDic:resDic isFunctionData:BanBu_Upload_My_Photos])
        {
            [_photoView clearEditData];
            _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
            _photoView.myPhotos = [_myProfile valueForKey:@"facelist"];
        }
        if([error.domain isEqualToString:BanBuDataformatError])
        {
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        return;
    }
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Set_My_Face_Default])
    {
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"modifySucceed", nil) activityAnimated:NO duration:1];
            NSMutableDictionary *infoUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
            [infoUpdata setValue:[resDic valueForKey:@"uface"] forKey:@"uface"];
            [UserDefaults setValue:infoUpdata forKey:MyAppDataManager.useruid];
            [UserDefaults synchronize];
            _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
            
            _photoView.myPhotos = [_myProfile valueForKey:@"facelist"];
            
            
        }
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"modifyFail", nil) activityAnimated:NO duration:1];
        }
    }
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Set_User_Sns_Idlist])
    {
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            [UserDefaults setValue:_socialInfo forKey:@"snslist"];
            [UserDefaults synchronize];
        }
        else
        {
            [_socialInfo removeAllObjects];
            [_socialInfo addEntriesFromDictionary:[UserDefaults valueForKey:@"snslist"]];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
        }
    }
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_User_Sns_Idlist])
    {
        [_socialInfo removeAllObjects];
        [_socialInfo addEntriesFromDictionary:[resDic valueForKey:@"snslist"]];
    }
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_My_Info])
    {

        NSMutableDictionary *infoUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
        [infoUpdata addEntriesFromDictionary:resDic];
        [infoUpdata removeObjectsForKeys:[NSArray arrayWithObjects:@"ok",@"fc",nil]];
        [UserDefaults setValue:infoUpdata forKey:MyAppDataManager.useruid];
        [UserDefaults synchronize];
        
        _myProfile = [[NSMutableDictionary alloc] initWithDictionary:[self buildMyProfile:infoUpdata]];
        [self.tableView reloadData];
        _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
        _photoView.myPhotos = [resDic valueForKey:@"facelist"];
        
        for(NSDictionary *url in _photoView.myPhotos)
        {
            if([[url valueForKey:@"facefile"] rangeOfString:@"system"].location!=NSNotFound)
            {
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"userinfor_photosystem", nil) activityAnimated:NO duration:3];
            }
        }
        
    }
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Set_My_Info])
    {
//        return;
        [UserDefaults setValue:[NSNumber numberWithBool:NO] forKey:@"isNewRegister"];//新注册用户
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"modifySucceed", nil) activityAnimated:NO duration:1];
            //            NSLog(@"%@",_checkingData);
            //            NSLog(@"%@",_editBuffer);
            [_checkingData setValue:[NSDate date] forKey:@"modifyDate"];
            
            //2014/07/24 by yinlinlin 修改,在本地保存所有的修改数据，而不是保存最后一个
            NSMutableDictionary * checkDict = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:[NSString stringWithFormat:@"modify%@",MyAppDataManager.useruid]]];
            [checkDict addEntriesFromDictionary:_checkingData];
            [UserDefaults setValue:checkDict forKey:[NSString stringWithFormat:@"modify%@",MyAppDataManager.useruid]];
            
            [UserDefaults synchronize];
            
            [_checkingData removeAllObjects];
            
            if([_editBuffer.allKeys indexOfObject:@"borndate"]!= NSNotFound)
            {
                NSInteger age = 0;
                NSInteger currentDate[3];
                NSInteger pickDate[3];
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                [formatter setDateFormat:@"yyyy-MM-dd"];
                
                NSArray *pickDateArr = [[_editBuffer valueForKey:@"borndate"] componentsSeparatedByString:@"-"];
                NSArray *nowDateArr = [[formatter stringFromDate:[NSDate date]] componentsSeparatedByString:@"-"];
                [formatter release];
                
                for(int i=0; i<3; i++)
                {
                    pickDate[i] = [[pickDateArr objectAtIndex:i] intValue];
                    currentDate[i] = [[nowDateArr objectAtIndex:i] intValue];
                }
                
                age = currentDate[0] - pickDate[0];
                if((currentDate[1]>pickDate[1]) ||((currentDate[1]==pickDate[1]) && (currentDate[2]>pickDate[2])))
                    age ++;
                [_editBuffer removeObjectForKey:@"borndate"];
                [_editBuffer setValue:[NSString stringWithFormat:@"%d",age] forKey:@"oldyears"];
                
            }
//            NSDictionary *mapDic = [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"s0c2", nil),@"sayme",NSLocalizedString(@"s2c0", nil),@"liked",NSLocalizedString(@"s2c1", nil),@"lovego",NSLocalizedString(@"s2c2", nil),@"company",NSLocalizedString(@"s2c3", nil),@"jobtitle",NSLocalizedString(@"s2c4", nil),@"school",NSLocalizedString(@"s1c0", nil),@"hbody",NSLocalizedString(@"s1c2", nil),@"wbody",NSLocalizedString(@"s1c1", nil),@"xblood",NSLocalizedString(@"nameLabel", nil),@"pname",NSLocalizedString(@"ageLabel", nil),@"oldyears",NSLocalizedString(@"sexSelect", nil),@"gender",nil];
//            
//            for(NSString *key in [_editBuffer allKeys])
//            {
//                NSMutableDictionary *item = [NSMutableDictionary dictionaryWithDictionary:[_myProfile valueForKey:[mapDic valueForKey:key]]];
//                [item setValue:[MyAppDataManager IsMinGanWord:[_editBuffer valueForKey:key]] forKey:@"realValue"];
//                [_myProfile setValue:item forKey:[mapDic valueForKey:key]];
//            }
            NSMutableDictionary *infoUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
            [infoUpdata addEntriesFromDictionary:resDic];
            [infoUpdata removeObjectsForKeys:[NSArray arrayWithObjects:@"ok",@"fc",nil]];
            [UserDefaults setValue:infoUpdata forKey:MyAppDataManager.useruid];
            [UserDefaults synchronize];
            
//            _myProfile = [[NSMutableDictionary alloc] initWithDictionary:[self buildMyProfile:infoUpdata]];
//            [self createHeaderView];
            //            [self.tableView reloadData];
            
            [self.editBuffer removeAllObjects];
            self.editBuffer = nil;
//            [self.tableView reloadData];
            
        }
        else
        {
            [self.editBuffer removeAllObjects];
            self.editBuffer = nil;
            if([[resDic valueForKey:@"error"] isEqualToString:@"__loginidinvalid__"]){
                [self.navigationController popToRootViewControllerAnimated:NO];
            }
        }
        
        
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Del_My_Avatar])
    {
        NSLog(@"%@",resDic);
        _photoView.delPhotoArr = nil;
        if(![[resDic valueForKey:@"ok"] boolValue]){
            if([[resDic allKeys] indexOfObject:@"error"] != NSNotFound)
            {
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:[MyAppDataManager IsInternationalLanguage:[resDic valueForKey:@"error"]] activityAnimated:NO duration:1];
            }
            _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
            _photoView.myPhotos = [_myProfile valueForKey:@"facelist"];
            
        }else{
            
            
            if([[resDic valueForKey:@"error"] isEqualToString:@"__loginidinvalid__"]){
                [self.navigationController popToRootViewControllerAnimated:NO];
                
            }
            
            //            else
            //            {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"updateAvatarSuccess", nil) activityAnimated:NO duration:1.0];
            
            //            }
            
            //更新本地文件字典用用户useruid关键字的字典
            NSMutableDictionary *faceidUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
            if([[resDic valueForKey:@"facelist"]count]){
                [faceidUpdata setValue:[resDic valueForKey:@"facelist"] forKey:@"facelist"];
                [faceidUpdata setValue:[[[resDic valueForKey:@"facelist"]objectAtIndex:0] valueForKey:@"facefile"] forKey:@"uface"];
            }
            [UserDefaults setValue:faceidUpdata forKey:MyAppDataManager.useruid];
            //同步
            [UserDefaults synchronize];
            //            NSLog(@"%@",[UserDefaults valueForKey:MyAppDataManager.useruid]);
            //如果添加头像数组为空的话 开始设置用户头像，防止用户仅剩一张头像添加一张删除一张头像造成的删除先完成而取不到头像的bug
            if(_photoView.addPhotoArr.count == 0)
                
            {
                MyAppDataManager.userAvatar = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
                _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
                _photoView.myPhotos = [resDic valueForKey:@"facelist"];
            }
            
            
            
        }
        if(_photoView.addPhotoArr.count){
            
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"sendAvater", nil) activityAnimated:YES];
            
        }
        
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Upload_My_Photos]){
        [_photoView clearEditData];
        if([[resDic valueForKey:@"ok"]boolValue]){
            [UserDefaults setValue:[NSNumber numberWithBool:NO] forKey:@"isNewRegister"];
            if(![[resDic valueForKey:@"successNum"] integerValue])
            {
                _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
                _photoView.myPhotos = [_myProfile valueForKey:@"facelist"];
            }
            else
            {
                //更新本地文件字典用用户useruid关键字的字典
                NSMutableDictionary *faceidUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
                [faceidUpdata setValue:[resDic valueForKey:@"facelist"] forKey:@"facelist"];
                [faceidUpdata setValue:[[[resDic valueForKey:@"facelist"]objectAtIndex:0] valueForKey:@"facefile"] forKey:@"uface"];
                [UserDefaults setValue:faceidUpdata forKey:MyAppDataManager.useruid];
                
                //开始同步
                [UserDefaults synchronize];
            }
        }
        
        //修改第三处缓存
        MyAppDataManager.userAvatar = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
        _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
        _photoView.myPhotos = [resDic valueForKey:@"facelist"];
        
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"updateAvatarSuccess", nil) activityAnimated:NO duration:1.0];
        
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Set_User_accountbind]){
        if([[resDic valueForKey:@"ok"]boolValue]){
            //NSLog(@"%@",resDic);
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
            NSString *langauage=[self getPreferredLanguage];
            if([langauage isEqual:@"zh-Hans"]){
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"reBindingSuccess", nil) activityAnimated:NO duration:2.0];
                
            }else{
                if([[UserDefaults valueForKey:@"FBUser"]isEqualToString:@""] || [[UserDefaults valueForKey:@"TUser"]isEqualToString:@""]){
                    [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"reBindingSuccess", nil) activityAnimated:NO duration:2.0];
                    
                }
                
            }
            
            NSMutableDictionary *bindUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
            
            [bindUpdata setValue:[resDic valueForKey:@"bindlist"] forKey:@"bindlist"];
            
            [UserDefaults setValue:bindUpdata forKey:MyAppDataManager.useruid];
            
        }
        else{
            if([[resDic valueForKey:@"error"] isEqualToString:@"__loginidinvalid__"]){
                [self.navigationController popToRootViewControllerAnimated:NO];
            }
        }
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_My_Facelist]){
        
        if([[resDic valueForKey:@"ok"] boolValue]){
            //            NSLog(@"%@",resDic);
            _photoView.uface    = [[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"uface"];
            _photoView.myPhotos = [resDic valueForKey:@"facelist"];
            
            //            NSMutableDictionary*faceUpdate = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyProfile]];
            //            [faceUpdate setValue:[resDic valueForKey:@"facelist"] forKey:@"facelist"];
            //            [UserDefaults setValue:faceUpdate forKey:MyProfile];
            //            [UserDefaults synchronize];
            
        }
    }
    
}

#pragma mark - BanBu_TextEditer delegate Method
- (void)banBuTextEditerDidChangeValue:(NSString *)newValue forItem:(NSString *)item
{
    NSString *langauage=[[MyAppDataManager getPreferredLanguage]substringToIndex:2];
    
    if([langauage isEqual:@"en"]){
        
        shareString = [[NSString alloc]initWithFormat:@"I've update my profile in Koochat(www.halfarea.com).%@ have changed to:%@ ",item,newValue];
    }else if([langauage isEqual:@"ja"]){
        shareString = [[NSString alloc]initWithFormat:@"私は私のプロフィール(www.halfarea.com)を更新しました.%@ 更新：%@",item,newValue];
    }
    
    //个人签名 兴趣爱好 常出没的地方 公司 职业 学校等
    NSDictionary *mapDic = [NSDictionary dictionaryWithObjectsAndKeys:@"sayme",NSLocalizedString(@"s0c2", nil),@"liked",NSLocalizedString(@"s2c0", nil),@"lovego",NSLocalizedString(@"s2c1", nil),@"company",NSLocalizedString(@"s2c2", nil),@"jobtitle",NSLocalizedString(@"s2c3", nil),@"school",NSLocalizedString(@"s2c4", nil),@"hbody",NSLocalizedString(@"s1c0", nil),@"wbody",NSLocalizedString(@"s1c2", nil),@"xblood",NSLocalizedString(@"s1c1", nil),@"pname",NSLocalizedString(@"nameLabel", nil),@"borndate",NSLocalizedString(@"ageLabel", nil),@"gender",NSLocalizedString(@"sexSelect", nil),nil];
    //borndate
    if(!self.editBuffer)
    {
        _editBuffer = [[NSMutableDictionary alloc] initWithCapacity:1];
    }
    if(!self.checkingData)
    {
        _checkingData = [[NSMutableDictionary alloc] initWithCapacity:1];
    }
    [_editBuffer setValue:newValue.length?newValue:@"" forKey:[mapDic valueForKey:item]];
    
    if([[mapDic valueForKey:item] isEqualToString:@"pname"])
    {
        self.title = newValue;
    }
    if([[mapDic valueForKey:item] isEqualToString:@"wbody"])
    {
        //        NSString *value = nil;
        if([newValue isEqualToString:@"a"]){newValue = @"< 40"; }
        else
            if([newValue isEqualToString:@"b"]){newValue = @"40-50";}
            else
                if([newValue isEqualToString:@"c"]){newValue = @"50-60";}
                else
                    if([newValue isEqualToString:@"d"]){newValue = @"60-70";}
                    else
                        if([newValue isEqualToString:@"e"]){newValue = @"> 70"; }
                        else
                        {newValue = @"";     }
        
    }
    if([[mapDic valueForKey:item] isEqualToString:@"hbody"])
    {
        if([newValue isEqualToString:@"a"]){newValue = @"< 165"; }
        else
            if([newValue isEqualToString:@"b"]){newValue = @"165-170";}
            else
                if([newValue isEqualToString:@"c"]){newValue = @"170-175";}
                else
                    if([newValue isEqualToString:@"d"]){newValue = @"175-180";}
                    else
                        if([newValue isEqualToString:@"e"]){newValue = @"> 180"; }
                        else
                        {newValue = @"";     }
    }
    if([[mapDic valueForKey:item] isEqualToString:@"xblood"])
    {
        if([newValue isEqualToString:@"a"]){newValue = @"A"; }
        else
            if([newValue isEqualToString:@"b"]){newValue = @"B"; }
            else
                if([newValue isEqualToString:@"o"]){newValue = @"O"; }
                else
                    if([newValue isEqualToString:@"c"]){newValue = @"AB";}
                    else
                    {newValue = @"";  }
    }
    

    if(![[mapDic valueForKey:item]isEqualToString:@"borndate"])
    {
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[_myProfile valueForKey:item]];
        [dic setValue:newValue.length?newValue:@"-" forKey:@"realValue"];
        
        if([newValue isEqualToString:[[_myProfile valueForKey:item] valueForKey:@"realValue"]])
        {
            return;
        }
        [_myProfile setValue:dic forKey:item];
    }
    else
    {
        NSInteger age = 0;
        NSInteger currentDate[3];
        NSInteger pickDate[3];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        
        NSArray *pickDateArr = [newValue componentsSeparatedByString:@"-"];
        NSArray *nowDateArr = [[formatter stringFromDate:[NSDate date]] componentsSeparatedByString:@"-"];
        [formatter release];
        
        for(int i=0; i<3; i++)
        {
            pickDate[i] = [[pickDateArr objectAtIndex:i] intValue];
            currentDate[i] = [[nowDateArr objectAtIndex:i] intValue];
        }
        
        age = currentDate[0] - pickDate[0];
        if((currentDate[1]>pickDate[1]) ||((currentDate[1]==pickDate[1]) && (currentDate[2]>pickDate[2])))
            age ++;
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[_myProfile valueForKey:item]];
        [dic setValue:[NSString stringWithFormat:@"%d",age] forKey:@"realValue"];
        if([[NSString stringWithFormat:@"%d",age] isEqualToString:[[_myProfile valueForKey:item] valueForKey:@"realValue"]])
        {
            return;
        }
        [_myProfile setValue:dic forKey:item];
    }
    
    NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"changeInfo", nil),item];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"noticeNotice", nil)
                                                    message:msg
                                                   delegate:self
                                          cancelButtonTitle:NSLocalizedString(@"cancelNotice", nil)
                                          otherButtonTitles:NSLocalizedString(@"saveButton", nil), nil];
    alert.tag = 100;
    [alert show];
    [alert release];
    [_checkingData setValue:newValue forKey:[mapDic valueForKey:item]];
    [self.tableView reloadData];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == alertView.cancelButtonIndex)
    {
        self.editBuffer = nil;
        [self.checkingData removeAllObjects];
        _myProfile = [[NSMutableDictionary alloc] initWithDictionary:[self buildMyProfile:[UserDefaults valueForKey:MyAppDataManager.useruid]]];
        [self.tableView reloadData];
        [UIView animateWithDuration:0.3 animations:^{
            self.view.userInteractionEnabled = NO;
            [_photoView setMyPhotos:[_myProfile valueForKey:@"facelist"]];
        } completion:^(BOOL finish){
            self.view.userInteractionEnabled = YES;
        }];
        
        [_photoView clearEditData];
        return;
        
    }
    if(_editBuffer.allKeys.count)
    {
        NSLog(@"%@",_editBuffer);
        [AppComManager getBanBuData:BanBu_Set_My_Info par:_editBuffer delegate:self];
        self.navigationController.view.userInteractionEnabled = NO;
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"updateInfo", nil) activityAnimated:YES];
    }
}





@end
